package com.kingyea.app.market.area.service.impl;

import com.kingyea.app.market.area.bean.Area;
import com.kingyea.app.market.area.dao.AreaMapper;
import com.kingyea.app.market.area.service.AreaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description Area 实现类
 * @date Created in 2018-03-25 21:47:16
 */
@Service
@Transactional
public class AreaServiceImpl implements AreaService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AreaServiceImpl.class);

    @Resource
    private AreaMapper areaMapper;

    /**
     * 通过ID查找对象
     *
     * @param code
     * @return
     */
    @Override
    public Area getById(Long code) throws Exception {
        return this.areaMapper.getById(code);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public List<Area> list(Area area) throws Exception {
        List<Area> list = areaMapper.list(area);
        return list;
    }

    /**
     * 删除
     *
     * @param code
     * @return
     */
    @Override
    public int deleteById(Long code) throws Exception {
        areaMapper.deleteById(code);
        return 1;
    }

    /**
     * 保存
     *
     * @param area
     * @return
     */
    @Override
    public Area save(Area area) throws Exception {
        try {
            areaMapper.save(area);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return area;
    }

    /**
     * 更新
     *
     * @param area
     * @return
     */
    @Override
    public Area update(Area area) throws Exception {
        try {
            areaMapper.update(area);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return area;
    }

    @Override
    public Integer size() {
        return areaMapper.size();
    }


}
